package com.cyw.search.controller;

import cn.easyes.core.biz.PageInfo;
import com.cyw.common.core.controller.BaseController;
import com.cyw.common.core.domain.R;
import com.cyw.common.core.domain.entity.SysUser;
import com.cyw.search.entity.user.EsUser;
import com.cyw.search.mapper.EsUserMapper;
import com.cyw.search.service.SearchEsUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Chenyw
 * @Date: 2022/08/21/22:21
 */
@Api(value = "用户接口", tags = {"用户接口"})
@RestController
@RequestMapping("/search/user")
public class EsUserController extends BaseController {

    @Resource
    private SearchEsUserService searchEsUserService;

    @Resource
    private EsUserMapper esUserMapper;
    @GetMapping("add")
    public R addUser(){
        EsUser esUser = new EsUser();
        esUser.setUserId(2L);
        esUser.setAddress("北京市昌平区");
        esUser.setLocation("39.91667,116.41667");
        esUserMapper.insert(esUser);
        return R.ok();
    }

    @ApiOperation("查询我的信息")
    @GetMapping("aboutMe")
    public R aboutMe(){
    return R.ok(searchEsUserService.aboutMe());
    }

    @ApiOperation("更新我的地理位置")
    @GetMapping("follow")
    public R follow(@ApiParam("经纬度") @RequestParam("geoPoint") String geoPoint){
        return searchEsUserService.updateGeoPoint(geoPoint);
    }

    @ApiOperation("分页查看附近的人")
    @GetMapping("searchNearUsers")
    public R<PageInfo<EsUser>> searchNearMoments(@ApiParam("经纬度字符串->(纬,经)") @RequestParam("geoPoint") String geoPoint,
                                                 @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                 @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return R.ok(searchEsUserService.searchNearUsers(geoPoint,pageNum,pageSize));
    }

    @ApiOperation("关注/取关")
    @GetMapping("followOrUnFollow")
    public R followOrUnFollow(@ApiParam("目标用户id") @RequestParam("userId") Long userId){
        return searchEsUserService.followOrUnFollow(userId);
    }

    @ApiOperation("查询我关注的数量以及关注我的数量")
    @GetMapping("loveContent")
    public R love(){
        return searchEsUserService.loveCount();
    }

    @ApiOperation("查询热门用户")
    @GetMapping("getHotUser")
    public R<List<SysUser>> getHotUser(){
        return R.ok(searchEsUserService.getHotUser());
    }

    @ApiOperation("查询用户排名")
    @GetMapping("getRankUser")
    public R<List<SysUser>> getRankUser(){
        return R.ok(searchEsUserService.getRankUser());
    }

    @ApiOperation("查询我的粉丝")
    @GetMapping("getLoveMeUser")
    public R loveMeUser(@ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                        @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
    return R.ok(searchEsUserService.loveMeUser(pageNum,pageSize));
    }

    @ApiOperation("查询我的关注")
    @GetMapping("getILoveUser")
    public R iLoveUser(@ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                       @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
    return R.ok(searchEsUserService.iLoveUser(pageNum,pageSize));
    }

    @ApiOperation("查询我的好友")
    @GetMapping("getMyFriends")
    public R myFriends(@ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                       @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
    return R.ok(searchEsUserService.myFriends(pageNum,pageSize));
    }

}
